<template>
  <div class="login-container">
    <!-- 登录卡片 -->
    <el-card class="login-card" >
     
      
      <!-- 登录表单 -->
      <el-form 
     
        :model="loginForm" 
        :rules="loginRules" 
      
      
      >
        <!-- 用户名输入 -->
        <el-form-item prop="name">
          <el-input 
            v-model="loginForm.name" 
            placeholder="请输入用户名" 
           
            clearable
          ></el-input>
        </el-form-item>
        
        <!-- 密码输入 -->
        <el-form-item prop="pwd">
          <el-input 
            v-model="loginForm.pwd" 
            type="password" 
            placeholder="请输入密码" 
          
            clearable
            show-password
          ></el-input>
        </el-form-item>
        
       
       
        
        <!-- 登录按钮 -->
        <el-form-item>
          <el-button 
            type="primary" 
            class="login-button" 
            @click="handleLogin"
            
          >
            登录
          </el-button>
        </el-form-item>
     
      </el-form>
    </el-card>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import { useRouter } from 'vue-router'

import myaxios from '@/Http/RabbitHelp'
const router=useRouter()

// 登录表单数据
const loginForm = reactive({
  name: '',
  pwd: '',

})








// 处理登录
const handleLogin =() => {





    myaxios.post("/api/Goods/Login",loginForm).then(res=>{
if(res.data.code==200){

ElMessage.success(res.data.message)
       // 登录成功，写JWT的 token到本地
        window.localStorage.setItem("token", res.data.data.token);
        // 数据提交后端要加入新的Token值
        myaxios.defaults.headers.common["Authorization"] =
            "Bearer " + res.data.data.token;
        router.push("/main")
      }else{
        ElMessage.error(res.data.message)
      }

})

    
   
  
}



</script>

<style scoped>
.login-container {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #f5f7fa;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  border-radius: 8px;
}

.login-header {
  text-align: center;
  padding: 20px 0;
}

.login-header h2 {
  margin: 0 0 10px 0;
  color: #1f2329;
}

.login-header p {
  margin: 0;
  color: #86909c;
  font-size: 14px;
}

.login-form {
  padding: 0 20px 20px;
}

.form-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.remember-checkbox {
  font-size: 14px;
}

.forgot-link {
  font-size: 14px;
}

.login-button {
  width: 100%;
  padding: 12px 0;
  font-size: 16px;
}

.other-login {
  margin-top: 20px;
  text-align: center;
}

.other-login span {
  display: inline-block;
  color: #86909c;
  font-size: 14px;
  margin-bottom: 15px;
}

.login-icons {
  display: flex;
  justify-content: center;
  gap: 20px;
}

.icon {
  font-size: 24px;
  color: #165dff;
  cursor: pointer;
  transition: color 0.3s;
}

.icon:hover {
  color: #0f48d2;
}

.code-image {
  width: 100%;
  height: 40px;
  cursor: pointer;
  overflow: hidden;
  border-radius: 4px;
}

.code-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
</style>
